<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    /**
    * @author NU SIT Bar
    * @version 2.0
    */
    Class Booking_prices{

        var $_CI;

        function __construct()
        {
            $this->_CI =& get_instance();

        }

        /**
        * 
        * Calculate location ( pickup and return ) prices
        * 
        */
        function step_2()
        {
            $tot_price = 0;

            // Pickup and Return location price
            $tot_price += $this->_CI->booking_session->get('pickup_loc_value');
            $tot_price += $this->_CI->booking_session->get('return_loc_value');

            $this->_CI->booking_session->set('tot_price',$tot_price);
        }

        /**
        * 
        * Calculate prices for booking days
        * @param car :: object
        */
        function step_3($car)
        {
            // first reset tot_price
            $this->step_2();

            // set tot_price for booking
            $no_days = $this->_CI->booking_session->get('no_days');
            $tot_price = $this->_CI->booking_session->get('tot_price');
            switch($no_days){

                case $no_days<=3:
                    $tot_price += $car->day13price*$no_days;
                    break;

                case $no_days>=4 && $no_days<=7:
                    $tot_price += $car->day47price*$no_days;
                    break;

                case $no_days>=8 && $no_days<=15:
                    $tot_price += $car->day815price*$no_days;
                    break;

                case $no_days>=15:
                    $tot_price += $car->dayfrom15price*$no_days;
                    break;
            }

            $this->_CI->booking_session->set('tot_price',$tot_price);
        }

        /*
        * Calculate prices for accessories, we call it extras :)
        * 
        * @param $accessoties:: Object
        * @param $car:: Object
        */
        function extras($accessories=NULL,$car=NULL)
        {
            // first reset tot_price
            $this->step_3($car);

            $no_days = $this->_CI->booking_session->get('no_days');
            $tot_price = $this->_CI->booking_session->get('tot_price');

            if($this->_CI->booking_session->get('extras')):

                if($accessories):

                    foreach($accessories as $row1):

                        foreach($this->_CI->booking_session->get('extras') as $val):

                            if($row1->id==$val){

                                $tot_price += (int)$row1->price*$no_days; 

                            }

                            endforeach;

                        endforeach;

                    endif;

                endif;

            $this->_CI->booking_session->set('tot_price',$tot_price);
        }
    }

?>
